package com.lizx.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lizx.admin.service.AdminProjectService;
import com.lizx.pojo.Employee;
import com.lizx.pojo.TbArea;
import com.lizx.pojo.TbProject;
import com.lizx.pojo.vo.TbProjectVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("admin/project")
public class AdminProjectController {

    @Resource
    AdminProjectService projectService;

    @RequestMapping("list")
    public String list(){
        return "admin/project/list";
    }

    @RequestMapping("getList")
    @ResponseBody
    public List<TbProject> getList(){
        return projectService.list();
    }

    @RequestMapping("selectListAll")
    @ResponseBody
    public List<TbProjectVo> selectListAll(){
        return projectService.selectListAll();
    }


    /**
     * 项目添加或修改
     * @param project
     */
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public void add(@RequestBody TbProject project){
        project.setStatus("1");
        projectService.saveOrUpdate(project);
    }

    /**
     * 项目回显
     * @param id
     * @return
     */
    @RequestMapping("findById/{id}")
    @ResponseBody
    public TbProject findById(@PathVariable int id){
        return projectService.getById(id);
    }

    /**
     * 根据项目id更新状态
     * @param id
     */
    @RequestMapping("updateStatus/{id}/{status}")
    @ResponseBody
    public void updateStatus(@PathVariable int id,@PathVariable String status){
        LambdaQueryWrapper<TbProject> queryWarpper = new LambdaQueryWrapper<TbProject>();
        queryWarpper.eq(TbProject::getId,id);
        TbProject project = new TbProject();
        project.setStatus(status);
        projectService.update(project,queryWarpper);
    }

}
